

/*

Author   : chaos

FileName : str_destructor.cpp

Date     : 11/08/17 22:22:55

*/
#include <iostream>
#include <cstring>
using namespace std;

class String
{
    private:
        char *string;
        long len;

    public:
        String(const char *i_string);
        ~String();
        void show_string();
};

void String::show_string(){
    cout <<"string : " << string << " length :" << len << endl;
}

String::String(const char* i_string){
    cout << "Constructor is called" << endl;
    len = strlen(i_string);
    string = new char (len+1);
    strcpy(string,i_string);
}

String::~String()
{
    cout << "Destructor is called !" << endl;
    delete [] string;
};

int main(int argc ,char *argv[])
{
    String * A_String = new String("My string");

    A_String->show_string();

    delete A_String;

    return 0;
}
